package com.sailfish.springbootdemo.dao.db5;

import com.sailfish.springbootdemo.common.DB5TableName;
import com.sailfish.springbootdemo.pojo.db5.EmpTDepartments;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface EmpTDepartmentsDao {

    /**
     * 根据dept_code查询部门
     *
     * @param deptCode
     * @return
     */
    @Results(id = "empTDepartmentsResultMap", value = {
            @Result(column = "dept_code", property = "deptCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sup_dept_code", property = "supDeptCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_name", property = "deptName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_enname", property = "deptEnname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "coa", property = "coa", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_code_chain", property = "deptCodeChain", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_name_chain", property = "deptNameChain", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_level", property = "deptLevel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_type", property = "deptType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "type_id", property = "typeId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "is_display", property = "isDisplay", jdbcType = JdbcType.VARCHAR),
            @Result(column = "coa_des", property = "coaDes", jdbcType = JdbcType.VARCHAR),
            @Result(column = "coa_des_en", property = "coaDesEn", jdbcType = JdbcType.VARCHAR),
    })
    @Select("select * from " + DB5TableName.EMP_T_DEPARTMENTS + " where dept_code = #{deptCode} limit 1")
    EmpTDepartments getEmpTDepartmentsByDeptCode(@Param("deptCode") String deptCode);

    /**
     * 根据 部门级别 和 父级 部门code查询 其下部门
     *
     * @param deptLevel
     * @param supDeptCode
     * @return
     */
    @Select("<script>" +
            "select * from " + DB5TableName.EMP_T_DEPARTMENTS + " where is_display = 1 and dept_level = #{deptLevel} " +
            "<if test='supDeptCode != null and supDeptCode != \"\" '>" +
            " and sup_dept_code = #{supDeptCode}" +
            "</if>" +
            "</script>")
    @ResultMap(value = "empTDepartmentsResultMap")
    List<EmpTDepartments> getEmpTDepartmentsByLevelAndSup(@Param("deptLevel") String deptLevel, @Param("supDeptCode") String supDeptCode);
}
